from pymilvus import MilvusClient
import typing as T
from fastapi import Depends
import logging
from .Configuration import configuration
from ..common.pool import MilvusPool, PoolConfig


_pool = MilvusPool(
    uri=f"http://{configuration.milvus.host}:{configuration.milvus.port}",
    db_name=configuration.milvus.db_name,
    username=configuration.milvus.username,
    password=configuration.milvus.password,
    config=PoolConfig(min_connections=configuration.milvus.pool_size),
)


async def get_embedding_client():
    async with _pool.acquire() as client:
        yield client


EmbeddingSession = T.Annotated[
    MilvusClient, Depends(get_embedding_client)
]  # 向量数据库

logging.info("向量数据库初始化完成...")
